package com.bsj.power.pls.netty;

import cn.hutool.core.map.BiMap;

import java.util.HashMap;

/**
 * 绑定clientId和设备id之间的关系
 */
public class CachedChannelMap {
    /**
     * 存储key clientId和value deviceId的双向查找的map
     */
    private static final BiMap<String, String> CHANNEL_MAP = new BiMap<>(new HashMap<>());

    public static void push(String clientId, String deviceId) {
        CHANNEL_MAP.put(clientId, deviceId);
    }

    public static String getDeviceId(String clientId) {
        return CHANNEL_MAP.get(clientId);
    }

    public static String getClientId(String deviceId) {
        return CHANNEL_MAP.getKey(deviceId);
    }

    public static void delClientId(String clientId) {
        CHANNEL_MAP.remove(clientId);
    }
}
